package com.haruhinav.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * code：
 * 小于0的都是失败(区别原因不同)
 * 大于等于0的成功
 *
 * -1:失败
 * 0：成功
 *
 *
 * 只在返回操作结果时使用这个类
 * 若返回数据库表数据不使用
 * */
@Data
//@AllArgsConstructor
//@NoArgsConstructor
public class ResultVO {

    private Integer code = 0;
    private String msg = "OK";
//  param type: success or warning or error
    private String type = "success";
    private Object data;


    public void fill(Integer code){
        fill(code,null);
    }
    public void fill(Integer code,String type){
        fill(code,type,null);
    }
    public void fill(Integer code,String type,String msg){
        fill(code,type,msg,null);
    }


    public void fill(Integer code,String type,String msg,Object data){
        this.code = code;
        this.msg = msg;
        this.type = type;
        this.data = data;
    }

    public static ResultVO success(){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg("OK");
        resultVO.setType("success");
        resultVO.setData(null);
        return resultVO;
    }
    public static ResultVO success(Integer code){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg("OK");
        resultVO.setType("success");
        resultVO.setData(null);
        return resultVO;
    }
    public static ResultVO success(Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg("OK");
        resultVO.setType("success");
        resultVO.setData(data);
        return resultVO;
    }
    public static ResultVO success(String msg){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg(msg);
        resultVO.setType("success");
        resultVO.setData(null);
        return resultVO;
    }
    public static ResultVO success(String msg,Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(0);
        resultVO.setMsg(msg);
        resultVO.setType("success");
        resultVO.setData(data);
        return resultVO;
    }
    public static ResultVO success(Integer code,String msg,Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setType("success");
        resultVO.setData(data);
        return resultVO;
    }
    public static ResultVO warning(Integer code,String msg){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setType("warning");
        resultVO.setData(null);
        return resultVO;
    }
    public static ResultVO warning(Integer code,String msg,Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setType("warning");
        resultVO.setData(data);
        return resultVO;
    }
    public static ResultVO fail(){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(-1);
        resultVO.setMsg("失败");
        resultVO.setType("error");
        resultVO.setData(null);
        return resultVO;
    }
    public static ResultVO fail(String msg){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(-1);
        resultVO.setMsg(msg);
        resultVO.setType("error");
        resultVO.setData(null);
        return resultVO;
    }
    public static ResultVO fail(String msg,Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(-1);
        resultVO.setMsg(msg);
        resultVO.setType("error");
        resultVO.setData(data);
        return resultVO;
    }
    public static ResultVO fail(Integer code,String msg,Object data){
        ResultVO resultVO = new ResultVO();
        resultVO.setCode(code);
        resultVO.setMsg(msg);
        resultVO.setType("error");
        resultVO.setData(data);
        return resultVO;
    }
}
